package com.ash.nio.tcp.channel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChannelDemo {

    public static void main(String[] args) throws URISyntaxException, IOException {


        File file = new File(ChannelDemo.class.getResource("/1.txt").toURI());
        System.out.println(file.length());

        FileInputStream fileInputStream = new FileInputStream(file);

        FileChannel inputStreamChannel = fileInputStream.getChannel();

        ByteBuffer allocate = ByteBuffer.allocate((int) file.length());

        inputStreamChannel.read(allocate);

        FileOutputStream fileOutputStream = new FileOutputStream(file.getParent() + "/2.txt");
        FileChannel outputStreamChannel = fileOutputStream.getChannel();

        allocate.flip();
        outputStreamChannel.write(allocate);


        fileInputStream.close();
        fileOutputStream.close();



    }
}
